#ifndef UUID_2C25A80349464B661486F28D168BDB8D
#define UUID_2C25A80349464B661486F28D168BDB8D

typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef int int32;
typedef unsigned long long uint64;

struct ByteWriter
{
	ByteWriter()
	: next(0), end(0)
	{
	}

	void put(unsigned char b)
	{
		if(next == end)
			overflow(this, b);
		else
			*next++ = b;
	}

	void flush()
	{
		overflow(this, -1);
	}

	unsigned char* next;
	unsigned char* end;
	void* user;

	void (*overflow)(ByteWriter* self, int b);
};

struct ByteReader
{
	ByteReader()
	: next(0), end(0)
	{
	}

	bool empty()
	{
		return next == end && !underflow(this);
	}

	unsigned char get()
	{
		return (next != end ? *next++ : fixUnderflow());
	}

	unsigned char fixUnderflow()
	{
		underflow(this);
		if(next != end)
			return *next++;
		return 0;
	}

	unsigned char const* next;
	unsigned char const* end;
	void* user;

	bool (*underflow)(ByteReader* self);
};

#endif // UUID_2C25A80349464B661486F28D168BDB8D
